<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // ES5 将变量作为对象的属性值
    var name = "张三";
    var age = 18;
    var height = "177cm";
    var weight = "70kg";

    var zhang = {
        // 键名: 键值(对应变量)
        "name": name,
        "age": age,
        "height": height,
        "weight": weight,
    }

    var zhang = {
        name: name,
        age: age,
        height: height,
        weight: weight,
    }
    console.log(zhang);

    // ES6 对象简写
    // 1. 将变量作为对象的属性值 =>  如果键名和键值对应的变量名相同, 可以省略键名(也可以理解合并)
    // var zhang = {
    //     name,
    //     age,
    //     height,
    //     weight,
    // }
    // console.log(zhang);


    // 2. ES6 对象中的函数可以直接简写  

    var obj = {
        a: 1,
        b: 2,
        // ES5
        // sum: function () {
        //     console.log(this.a, this.b);
        // },
        // ES6
        sum() {
            console.log(this.a, this.b);
        }
    }
    console.log(obj);

    obj.sum()




</script>

</html>